﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

[System.Serializable]
public class BehaviourNode : MonoBehaviour {
    public List<BehaviourNode> nodes;
    public bool running;

    internal BaseUnit Unit
    {
        get
        {
            return this.Unit();
        }
    }

    internal UnitAnimations Anim
    {
        get
        {
            return this.Anims();
        }
    }

    internal Destructible Destruct
    {
        get
        {
            return GetComponent<Destructible>();
        }
    }

    internal IEnumerator Test()
    {
        foreach (var n in nodes)
        {
            yield return StartCoroutine(n.Activate());
        }
    }

    public virtual IEnumerator Activate()
    {
        running = true;
        while (true)
        {
            foreach (var n in nodes)
            {
                yield return false;
                yield return StartCoroutine(n.Activate());
            }
        }
        running = false;
    }
}